using HKB.Common;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
namespace HKB.Web
{
	public class UserInfoBll
	{
		private Conn conn = null;
		public UserInfoBll()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public UserInfoBll(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable GetUserInfoByUserID(int UserID)
		{
			return this.conn.GetDataTable("Select I.*,U.UserName,U.RegTime,U.Sex From [HL_User] U Left Join [HL_UserInfo] I On I.UserID=U.UserID Where U.UserID=" + UserID);
		}
		public DataTable GetQQTaobaoByUserID(int UserID)
		{
			return this.conn.GetDataTable("Select I.ICQ, I.OICQ, I.MSN, I.Taobaowangwang, I.Fax, I.MobilePhone, U.UserName From [HL_UserInfo] I INNER JOIN  HL_User U ON I.UserID = U.UserID Where I.UserID=" + UserID);
		}
		public string GetUserNameByID(int id)
		{
			return (string)this.conn.GetScalar("Select UserName From [HL_User] Where UserID=" + id, new IDbDataParameter[0]);
		}
		public DataTable GetUserIdentifyByUserID(int UserID)
		{
			return this.conn.GetDataTable("SELECT I.UserInfoID, I.UserID,I.AuthenticationType, I.CompanyIdentify,I.MobileIdentify,I.BandShopIdentify,I.OtherIdentify1,I.OtherIdentify2,I.OtherIdentify3,I.OtherIdentify4,U.UserName FROM HL_UserInfo I INNER JOIN  HL_User U ON I.UserID = U.UserID WHERE (I.UserID = " + UserID + ")");
		}
		public DataTable GetUserByUserID(int UserID)
		{
			SqlParameter sqlParameter = new SqlParameter("@UserID", SqlDbType.Int, 4, ParameterDirection.Input, 10, 0, null, DataRowVersion.Current, false, null, "", "", "");
			sqlParameter.Value = UserID;
			return this.conn.GetDataTable("pr_GetShopByuserid", new SqlParameter[]
			{
				sqlParameter
			});
		}
		public DataTable GetUserInfoByShopID(int ShopID)
		{
			return this.conn.GetDataTable("Select * From [HL_UserInfo] ShopID=" + ShopID);
		}
		public DataTable GetShopUserBaseInfoByUserID(int UserID)
		{
			return this.conn.GetDataTable("SELECT * FROM HL_UserInfo INNER JOIN HL_User ON HL_UserInfo.UserID = HL_User.UserID WHERE (HL_UserInfo.UserID = " + UserID + ")");
		}
		public int GetUserInfoSaleCredietByShopID(int ShopID)
		{
			int result = 0;
			string sql = "select SaleCrediet from HL_UserInfo where ShopID=" + ShopID;
			DataTable dataTable = this.conn.GetDataTable(sql);
			if (dataTable.Rows.Count > 0)
			{
				if (dataTable.Columns.Contains("SaleCrediet"))
				{
					if (dataTable.Rows[0]["SaleCrediet"] != DBNull.Value)
					{
						result = Convert.ToInt32(dataTable.Rows[0]["SaleCrediet"].ToString());
					}
				}
			}
			return result;
		}
		public bool UpdateUserInfoByUserID(int UserID, string TrueName, string Address, string ZipCode, string OICQ, string Taobaowangwang, string MobilePhone, string HomePhone, string IDCard, string Province, string City)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@Province", DbType.String, Province),
				this.conn.CreateParameter("@City", DbType.String, City),
				this.conn.CreateParameter("@ZipCode", DbType.String, ZipCode),
				this.conn.CreateParameter("@Address", DbType.String, Address),
				this.conn.CreateParameter("@TrueName", DbType.String, TrueName),
				this.conn.CreateParameter("@IDCard", DbType.String, IDCard),
				this.conn.CreateParameter("@OICQ", DbType.String, OICQ),
				this.conn.CreateParameter("@HomePhone", DbType.String, HomePhone),
				this.conn.CreateParameter("@MobilePhone", DbType.String, MobilePhone),
				this.conn.CreateParameter("@Taobaowangwang", DbType.String, Taobaowangwang),
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID)
			};
			string commandText = "UPDATE [HL_UserInfo] SET [Province] = @Province, [City] = @City, [ZipCode] = @ZipCode, [Address] = @Address, [TrueName] = @TrueName, [IDCard] = @IDCard, [OICQ] = @OICQ, [HomePhone] = @HomePhone, [MobilePhone] = @MobilePhone, [Taobaowangwang] = @Taobaowangwang WHERE (([UserID] = @UserID))";
			int num = this.conn.Execute(commandText, parameters);
			return num == 1;
		}
		public bool UpdateUserInfoByUserID(string TrueName, string IDCard, string Province, string City, DateTime Birthday, string ComeFrom, string Country, string Eductation, string Family, string Fax, string GraduteSchool, string HomePage, string InCome, string intro, string Interests, int Marriage, string Nation, string Address, string ZipCode, string OICQ, string MSN, string Taobaowangwang, string MobilePhone, string HomePhone, string ICQ, string CompanyName, DateTime CreateTime, DateTime UpdateTime, int BuyCrediet, int SaleCrediet, int ShopID, int UserID)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@TrueName", DbType.String, TrueName),
				this.conn.CreateParameter("@IDCard", DbType.String, IDCard),
				this.conn.CreateParameter("@Birthday", DbType.DateTime, Birthday),
				this.conn.CreateParameter("@ComeFrom", DbType.String, ComeFrom),
				this.conn.CreateParameter("@Eductation", DbType.String, Eductation),
				this.conn.CreateParameter("@Family", DbType.String, Family),
				this.conn.CreateParameter("@Fax", DbType.String, Fax),
				this.conn.CreateParameter("@GraduteSchool", DbType.String, GraduteSchool),
				this.conn.CreateParameter("@HomePage", DbType.String, HomePage),
				this.conn.CreateParameter("@InCome", DbType.String, InCome),
				this.conn.CreateParameter("@intro", DbType.String, intro),
				this.conn.CreateParameter("@Interests", DbType.String, Interests),
				this.conn.CreateParameter("@Marriage", DbType.String, Marriage),
				this.conn.CreateParameter("@Nation", DbType.String, Nation),
				this.conn.CreateParameter("@ZipCode", DbType.String, ZipCode),
				this.conn.CreateParameter("@OICQ", DbType.String, OICQ),
				this.conn.CreateParameter("@MSN", DbType.String, MSN),
				this.conn.CreateParameter("@Taobaowangwang", DbType.String, Taobaowangwang),
				this.conn.CreateParameter("@MobilePhone", DbType.String, MobilePhone),
				this.conn.CreateParameter("@HomePhone", DbType.String, HomePhone),
				this.conn.CreateParameter("@ICQ", DbType.String, ICQ),
				this.conn.CreateParameter("@CompanyName", DbType.String, CompanyName),
				this.conn.CreateParameter("@CreateTime", DbType.DateTime, CreateTime),
				this.conn.CreateParameter("@UpdateTime", DbType.DateTime, UpdateTime),
				this.conn.CreateParameter("@BuyCrediet", DbType.Int32, BuyCrediet),
				this.conn.CreateParameter("@SaleCrediet", DbType.Int32, SaleCrediet),
				this.conn.CreateParameter("@ShopID", DbType.Int32, ShopID),
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID)
			};
			string commandText = "UPDATE [HL_UserInfo] SET [ZipCode] = @ZipCode, [ComeFrom] = @ComeFrom, [Nation] = @Nation, [Birthday] = @Birthday, [TrueName] = @TrueName, [IDCard] = @IDCard, [Marriage] = @Marriage, [Family] = @Family, [InCome] = @InCome, [Eductation] = @Eductation, [GraduteSchool] = @GraduteSchool, [Interests] = @Interests, [CreateTime] = @CreateTime, [UpdateTime] = @UpdateTime, [ICQ] = @ICQ, [OICQ] = @OICQ, [MSN] = @MSN, [HomePage] = @HomePage, [HomePhone] = @HomePhone, [MobilePhone] = @MobilePhone, [Fax] = @Fax, [Taobaowangwang] = @Taobaowangwang, [ShopID] = @ShopID, [SaleCrediet] = @SaleCrediet, [BuyCrediet] = @BuyCrediet, [CompanyName] = @CompanyName, [intro] = @intro WHERE (([UserID] = @UserID))";
			int num = this.conn.Execute(commandText, parameters);
			return num == 1;
		}
		public bool AddUserInfoByUserID(string TrueName, string IDCard, string Province, string City, DateTime Birthday, string ComeFrom, string Country, string Eductation, string Family, string Fax, string GraduteSchool, string HomePage, string InCome, string intro, string Interests, int Marriage, string Nation, string Address, string ZipCode, string OICQ, string MSN, string Taobaowangwang, string MobilePhone, string HomePhone, string ICQ, string CompanyName, DateTime CreateTime, DateTime UpdateTime, int BuyCrediet, int SaleCrediet, int ShopID, int UserID)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@TrueName", DbType.String, TrueName),
				this.conn.CreateParameter("@IDCard", DbType.String, IDCard),
				this.conn.CreateParameter("@Province", DbType.String, Province),
				this.conn.CreateParameter("@City", DbType.String, City),
				this.conn.CreateParameter("@Birthday", DbType.DateTime, Birthday),
				this.conn.CreateParameter("@ComeFrom", DbType.String, ComeFrom),
				this.conn.CreateParameter("@Country", DbType.String, Country),
				this.conn.CreateParameter("@Eductation", DbType.String, Eductation),
				this.conn.CreateParameter("@Family", DbType.String, Family),
				this.conn.CreateParameter("@Fax", DbType.String, Fax),
				this.conn.CreateParameter("@GraduteSchool", DbType.String, GraduteSchool),
				this.conn.CreateParameter("@HomePage", DbType.String, HomePage),
				this.conn.CreateParameter("@InCome", DbType.String, InCome),
				this.conn.CreateParameter("@intro", DbType.String, intro),
				this.conn.CreateParameter("@Interests", DbType.String, Interests),
				this.conn.CreateParameter("@Marriage", DbType.String, Marriage),
				this.conn.CreateParameter("@Nation", DbType.String, Nation),
				this.conn.CreateParameter("@Address", DbType.String, Address),
				this.conn.CreateParameter("@ZipCode", DbType.String, ZipCode),
				this.conn.CreateParameter("@OICQ", DbType.String, OICQ),
				this.conn.CreateParameter("@MSN", DbType.String, MSN),
				this.conn.CreateParameter("@Taobaowangwang", DbType.String, Taobaowangwang),
				this.conn.CreateParameter("@MobilePhone", DbType.String, MobilePhone),
				this.conn.CreateParameter("@HomePhone", DbType.String, HomePhone),
				this.conn.CreateParameter("@ICQ", DbType.String, ICQ),
				this.conn.CreateParameter("@CompanyName", DbType.String, CompanyName),
				this.conn.CreateParameter("@CreateTime", DbType.DateTime, CreateTime),
				this.conn.CreateParameter("@UpdateTime", DbType.DateTime, UpdateTime),
				this.conn.CreateParameter("@BuyCrediet", DbType.Int32, BuyCrediet),
				this.conn.CreateParameter("@SaleCrediet", DbType.Int32, SaleCrediet),
				this.conn.CreateParameter("@ShopID", DbType.Int32, ShopID),
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID)
			};
			string commandText = "Insert Into [HL_UserInfo]([Country], [Province], [City], [ZipCode], [Address], [ComeFrom], [Nation], [Birthday], [TrueName], [IDCard], [Marriage], [Family], [InCome], [Eductation], [GraduteSchool], [Interests], [CreateTime], [UpdateTime], [ICQ], [OICQ], [MSN], [HomePage], [HomePhone], [MobilePhone], [Fax], [Taobaowangwang], [ShopID], [SaleCrediet], [BuyCrediet], [CompanyName], [intro], [UserID]) Values(@Country, @Province, @City, @ZipCode, @Address, @ComeFrom, @Nation, @Birthday, @TrueName, @IDCard, @Marriage, @Family, @InCome, @Eductation, @GraduteSchool, @Interests, @CreateTime, @UpdateTime, @ICQ, @OICQ, @MSN, @HomePage, @HomePhone, @MobilePhone, @Fax, @Taobaowangwang, @ShopID, @SaleCrediet, @BuyCrediet, @CompanyName, @intro, @UserID)";
			int num = this.conn.Execute(commandText, parameters);
			return num == 1;
		}
	}
}
